﻿<UserControl x:Class="SoftTeach.View.Noten.ArbeitDetailView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
             xmlns:resources="clr-namespace:SoftTeach.Resources" 
             xmlns:softTeach="clr-namespace:SoftTeach" xmlns:noten="clr-namespace:SoftTeach.ViewModel.Noten"
             xmlns:sys="clr-namespace:System;assembly=mscorlib" 
             mc:Ignorable="d" 
             d:DesignHeight="276" d:DesignWidth="777">
  <UserControl.Resources>
    <!-- Value Converters -->
    <CollectionViewSource Source="{Binding Path=Schülereinträge}" x:Key="SchülerSorted">
      <CollectionViewSource.SortDescriptions>
        <scm:SortDescription PropertyName="SchülereintragPerson.PersonVorname" Direction="Ascending"/>
      </CollectionViewSource.SortDescriptions>
    </CollectionViewSource>

    <ObjectDataProvider MethodName="GetValues"
                          ObjectType="{x:Type sys:Enum}"
                          x:Key="Bepunktungstypen">
      <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="noten:Bepunktungstyp" />
      </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
    <ObjectDataProvider MethodName="GetValues"
                          ObjectType="{x:Type sys:Enum}"
                          x:Key="Notentypen">
      <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="noten:Notentyp" />
      </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

  </UserControl.Resources>
  <GroupBox Padding="5" Header="Arbeit" Margin="5"
                HeaderTemplate="{StaticResource GroupBoxHeader}">
    <Grid x:Name="LayoutRoot">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="140"/>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="140"/>
          <ColumnDefinition Width="30"/>
          <ColumnDefinition Width="126"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Grid.Column="0">Bezeichnung</Label>
        <TextBox  Grid.Row="0" Grid.Column="1" Margin="3" Text="{Binding Path=ArbeitBezeichnung}"/>
        <Label Grid.Row="0" Grid.Column="2">Datum</Label>
        <DatePicker Grid.Row="0" Grid.Column="3"  Margin="3" IsEnabled="False" SelectedDate="{Binding Path=ArbeitDatum}"/>
        <Label Grid.Row="1" Grid.Column="0">Schuljahr</Label>
        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
          <ComboBox Margin="3,3,0,3" Width="62"
                ItemsSource="{Binding Source={x:Static softTeach:App.MainViewModel}, Path=Halbjahrtypen}" 
                SelectedItem="{Binding Path=ArbeitHalbjahrtyp}"
                DisplayMemberPath="HalbjahrtypBezeichnung"
                IsEnabled="False"
                Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}" 
                HorizontalAlignment="Left"/>
          <ComboBox Margin="0,3,3,3" Width="72"
                ItemsSource="{Binding Source={x:Static softTeach:App.MainViewModel}, Path=Jahrtypen}" 
                SelectedItem="{Binding Path=ArbeitJahrtyp}"
                DisplayMemberPath="JahrtypBezeichnung"
                    IsEnabled="False"
                    Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}"
                HorizontalAlignment="Left"/>
        </StackPanel>
        <StackPanel  Grid.Row="1" Grid.Column="2" Orientation="Horizontal">
          <Label>LfdNr.</Label>
          <Label Content="{Binding Path=ArbeitLfdNr}"/>
        </StackPanel>
        <CheckBox  Grid.Row="1" Grid.Column="3" Margin="3" TabIndex="1" Content="Klassenarbeit"
                    IsChecked="{Binding Path=ArbeitIstKlausur}"/>
        <Label  Grid.Row="2" Grid.Column="0">Fach</Label>
        <ComboBox  Grid.Row="2" Grid.Column="1" Margin="3" Width="134"
                ItemsSource="{Binding Source={x:Static softTeach:App.MainViewModel}, Path=Fächer}" 
                SelectedItem="{Binding Path=ArbeitFach}"
                DisplayMemberPath="FachBezeichnung"
                   IsEnabled="False"
                Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}"
                HorizontalAlignment="Left"/>
        <Label Grid.Row="2" Grid.Column="2">Klasse</Label>
        <ComboBox Grid.Row="2" Grid.Column="3" Margin="3" Width="134"
                ItemsSource="{Binding Source={x:Static softTeach:App.MainViewModel}, Path=Klassen}" 
                SelectedItem="{Binding Path=ArbeitKlasse}"
                DisplayMemberPath="KlasseBezeichnung"
                  IsEnabled="False"
                Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}"
                HorizontalAlignment="Left"/>
        <Label  Grid.Row="3" Grid.Column="0">Bewertungsschema</Label>
        <ComboBox  Grid.Row="3" Grid.Column="1" Margin="3" Width="134"
                ItemsSource="{Binding Source={x:Static softTeach:App.MainViewModel}, Path=Bewertungsschemata}" 
                SelectedItem="{Binding Path=ArbeitBewertungsschema}"
                DisplayMemberPath="BewertungsschemaBezeichnung"
                Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}"
                HorizontalAlignment="Left"/>
        <Label  Grid.Row="3" Grid.Column="2">Bepunktungstyp</Label>
        <ComboBox  Grid.Row="3" Grid.Column="3" Margin="3" TabIndex="1" Name="ComboBepunktungstyp"
                ItemsSource="{Binding Source={StaticResource Bepunktungstypen}}" 
                SelectedItem="{Binding Path=ArbeitBepunktungstyp}"
                Style="{StaticResource {x:Static ToolBar.ComboBoxStyleKey}}" Width="134"
                  HorizontalAlignment="Left"/>
        <Grid Grid.Row="1" Grid.Column="5" Grid.RowSpan="2" Background="WhiteSmoke">
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="1"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="1"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="1"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="1"/>
            <ColumnDefinition Width="20"/>
            <ColumnDefinition Width="1"/>
            <ColumnDefinition Width="20"/>
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition Height="1"/>
            <RowDefinition Height="25"/>
          </Grid.RowDefinitions>
          <Label Grid.Row="0" Grid.Column="0" Style="{StaticResource NotenschnittStyle}">1</Label>
          <Border Grid.Row="0" Grid.Column="1" Grid.RowSpan="3" BorderBrush="DarkGray" BorderThickness="1"/>
          <Label Grid.Row="0" Grid.Column="2" Style="{StaticResource NotenschnittStyle}">2</Label>
          <Border Grid.Row="0" Grid.Column="3" Grid.RowSpan="3" BorderBrush="DarkGray" BorderThickness="1"/>
          <Label Grid.Row="0" Grid.Column="4" Style="{StaticResource NotenschnittStyle}">3</Label>
          <Border Grid.Row="0" Grid.Column="5" Grid.RowSpan="3" BorderBrush="DarkGray" BorderThickness="1"/>
          <Label Grid.Row="0" Grid.Column="6" Style="{StaticResource NotenschnittStyle}">4</Label>
          <Border Grid.Row="0" Grid.Column="7" Grid.RowSpan="3" BorderBrush="DarkGray" BorderThickness="1"/>
          <Label Grid.Row="0" Grid.Column="8" Style="{StaticResource NotenschnittStyle}">5</Label>
          <Border Grid.Row="0" Grid.Column="9" Grid.RowSpan="3" BorderBrush="DarkGray" BorderThickness="1"/>
          <Label Grid.Row="0" Grid.Column="10" Style="{StaticResource NotenschnittStyle}">6</Label>
          <Border Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="11" BorderBrush="DarkGray" BorderThickness="1"/>
          <Label Grid.Row="2" Grid.Column="0" Style="{StaticResource NotenschnittStyle}" Content="{Binding Path=ArbeitAnzahlNoten1}"/>
          <Label Grid.Row="2" Grid.Column="2" Style="{StaticResource NotenschnittStyle}" Content="{Binding Path=ArbeitAnzahlNoten2}"/>
          <Label Grid.Row="2" Grid.Column="4" Style="{StaticResource NotenschnittStyle}" Content="{Binding Path=ArbeitAnzahlNoten3}"/>
          <Label Grid.Row="2" Grid.Column="6" Style="{StaticResource NotenschnittStyle}" Content="{Binding Path=ArbeitAnzahlNoten4}"/>
          <Label Grid.Row="2" Grid.Column="8" Style="{StaticResource NotenschnittStyle}" Content="{Binding Path=ArbeitAnzahlNoten5}"/>
          <Label Grid.Row="2" Grid.Column="10" Style="{StaticResource NotenschnittStyle}" Content="{Binding Path=ArbeitAnzahlNoten6}"/>
        </Grid>
        <Label Grid.Row="0" Grid.Column="5">Notenspiegel</Label>
        <Label Grid.Row="3" Grid.Column="5" Content="{Binding Path=ArbeitNotendurchschnittString}"/>
      </Grid>

      <GroupBox Grid.Row="1" Header="Aufgaben" Margin="5">
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
          </Grid.RowDefinitions>
          <Grid Grid.Row="0" Margin="3">
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" Orientation="Horizontal">
              <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" 
                      Command="{Binding Path=AddAufgabeCommand}">
                <StackPanel Orientation="Horizontal" ToolTip="Aufgabe hinzufügen">
                  <Grid >
                    <Image Source="/SoftTeach;component/Images/Aufgabe16.png"/>
                    <Image Source="/SoftTeach;component/Images/AddOverlay16.png"/>
                  </Grid>
                  <Label Padding="5,0,0,0" VerticalContentAlignment="Center">Aufgabe hinzufügen</Label>
                </StackPanel>
              </Button>
              <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" 
                      Command="{Binding Path=EditAufgabeCommand}">
                <StackPanel Orientation="Horizontal" ToolTip="Aufgabe bearbeiten">
                  <Grid >
                    <Image Source="/SoftTeach;component/Images/Aufgabe16.png"/>
                    <Image Source="/SoftTeach;component/Images/EditOverlay16.png"/>
                  </Grid>
                  <Label Padding="5,0,0,0" VerticalContentAlignment="Center">Aufgabe bearbeiten</Label>
                </StackPanel>
              </Button>
              <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" 
                      Command="{Binding Path=DeleteAufgabeCommand}">
                <StackPanel Orientation="Horizontal" ToolTip="Aufgabe entfernen">
                  <Grid >
                    <Image Source="/SoftTeach;component/Images/Aufgabe16.png"/>
                    <Image Source="/SoftTeach;component/Images/RemoveOverlay16.png"/>
                  </Grid>
                  <Label Padding="5,0,0,0" VerticalContentAlignment="Center">Aufgabe entfernen</Label>
                </StackPanel>
              </Button>
              <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" 
                      Command="{Binding Path=PrintNotenlisteCommand}">
                <StackPanel Orientation="Horizontal" ToolTip="Notenliste drucken">
                  <Grid >
                    <Image Source="/SoftTeach;component/Images/Note16.png"/>
                    <Image Source="/SoftTeach;component/Images/PrintOverlay16.png"/>
                  </Grid>
                  <Label Padding="5,0,0,0" VerticalContentAlignment="Center">Notenliste drucken</Label>
                </StackPanel>
              </Button>
            </StackPanel>
            <Border Grid.Column="1" CornerRadius="5">
              <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
                <Label Padding="3">Gesamtpunktzahl:</Label>
                <Label Padding="3" Content="{Binding Path=ArbeitGesamtpunktzahl}"/>
              </StackPanel>
            </Border>
          </Grid>
          <DataGrid Grid.Row="1" Name="NotenGrid"
                  SelectedItem="{Binding Path=CurrentSchülereintrag}" 
                  ItemsSource="{Binding Source={StaticResource SchülerSorted}}" 
                  AutoGenerateColumns="False"
                  CanUserAddRows="False">
            <DataGrid.Columns>
              <DataGridTextColumn Binding="{Binding SchülereintragPerson.PersonVorname}" Header="Vorname" IsReadOnly="True"/>
              <DataGridTextColumn Binding="{Binding SchülereintragPerson.PersonNachname}" Header="Nachname" IsReadOnly="True"/>
              <DataGridTemplateColumn Width="*">
                <DataGridTemplateColumn.HeaderStyle>
                  <Style TargetType="DataGridColumnHeader">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                    <Setter Property="VerticalContentAlignment" Value="Stretch" />
                    <Setter Property="Margin" Value="0" />
                    <Setter Property="ContentTemplate">
                      <Setter.Value>
                        <DataTemplate>
                          <ItemsControl ItemsSource="{Binding DataContext.Aufgaben, ElementName=LayoutRoot}">
                            <ItemsControl.ItemsPanel>
                              <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal"/>
                              </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                              <DataTemplate>
                                <Border Width="70">
                                  <TextBlock Text="{Binding Path=AufgabeColumnHeader}" HorizontalAlignment="Center">
                                    <TextBlock.InputBindings>
                                      <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding Path=EditAufgabeCommand}"/>
                                    </TextBlock.InputBindings>
                                  </TextBlock>
                                </Border>
                              </DataTemplate>
                            </ItemsControl.ItemTemplate>
                          </ItemsControl>
                        </DataTemplate>
                      </Setter.Value>
                    </Setter>
                  </Style>
                </DataGridTemplateColumn.HeaderStyle>
                <DataGridTemplateColumn.CellTemplate>
                  <DataTemplate>
                    <ItemsControl ItemsSource="{Binding CurrentArbeitErgebnisse}">
                      <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                          <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                      </ItemsControl.ItemsPanel>
                      <ItemsControl.ItemTemplate>
                        <DataTemplate>
                          <Border Width="70">
                            <TextBlock Text="{Binding Path=ErgebnisPunktzahl}" TextAlignment="Center"/>
                          </Border>
                        </DataTemplate>
                      </ItemsControl.ItemTemplate>
                    </ItemsControl>
                  </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                  <DataTemplate>
                    <ItemsControl ItemsSource="{Binding CurrentArbeitErgebnisse}">
                      <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                          <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                      </ItemsControl.ItemsPanel>
                      <ItemsControl.ItemTemplate>
                        <DataTemplate>
                          <Border Width="70">
                            <TextBox Text="{Binding Path=ErgebnisPunktzahl}" TextAlignment="Center"/>
                          </Border>
                        </DataTemplate>
                      </ItemsControl.ItemTemplate>
                    </ItemsControl>
                  </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
              </DataGridTemplateColumn>
              <DataGridTextColumn Binding="{Binding CurrentArbeitPunktsumme}" Header="Summe" IsReadOnly="True"/>
              <DataGridTextColumn Binding="{Binding CurrentArbeitNote}" Header="Note" IsReadOnly="True"/>
            </DataGrid.Columns>


            <!--global:DataGridColumnsBehavior.BindableColumns="{Binding AufgabenColumns}"-->
            <!--Tag="{Binding Path=AufgabenColumns, NotifyOnTargetUpdated=True}" TargetUpdated="OnTargetUpdated" Unloaded="NotenGrid_Unloaded">-->
            <!--Style="{StaticResource AufgabeDataGridStyle}"-->
            <!--ColumnHeaderStyle="{StaticResource AufgabenColumnHeaderStyle}">-->
          </DataGrid>
        </Grid>
      </GroupBox>
    </Grid>
  </GroupBox>
</UserControl>
